/**
 * Created by CZ on 2017/4/11.
 */
module.exports = function ($state,$modal,$localStorage,commonConfig) {
    return{
        openTipsModel:function(content,page,survey,item){
            $modal.open({
                animation: true,
                templateUrl: './views/model/LoadingModel.html',
                size: 'md',
                controller: function($scope,$modalInstance,$timeout,$state) {
                    $scope.content = content;
                    $timeout(function(){
                        $modalInstance.close();
                        if(page && survey && item){
                            console.log(survey,item);
                            $state.go(page,{'surveyId':survey,'itemId':item});
                            return
                        }else if(page && survey){
                            console.log(survey);
                            $state.go(page,{'surveyId':survey});
                            return
                        }else if(page){
                            $state.go(page);
                        }

                    },1000);
                }
            });
        },
        openAlertModel:function(content){
            $modal.open({
                animation: true,
                templateUrl: './views/model/AlertModel.html',
                size: 'md',
                controller: function($scope,$modalInstance) {
                    $scope.content = content;
                    $scope.ok = function () {
                        $modalInstance.close();
                    };

                }
            });
        },
        openExitModel:function(content,page,KeyName){
            $modal.open({
                animation: true,
                templateUrl: './views/model/ExitModel.html',
                size: 'md',
                controller: function($scope,$modalInstance) {
                    $scope.content = content;
                    $scope.ok = function () {
                        console.log(page,KeyName);
                        $localStorage.remove(KeyName);
                        //刷新页面
                        // if(KeyName == 'cloud'){
                        //     history.go(0);
                        // }
                        // $state.go(page);

                        $modalInstance.close();
                        window.location.href = commonConfig.tokenApi+'login?logout';
                    };
                    $scope.cancel = function(){
                        $modalInstance.close();
                    }
                }
            });
        }
    };

};